<?php
// +----------------------------------------------------------------------
//            -------------------------
//           /   / ----------------\  \
//          /   /             \  \
//         /   /              /  /
//        /   /    /-------------- /  /
//       /   /    /-------------------\  \
//      /   /                   \  \
//     /   /                     \  \
//    /   /                      /  /
//   /   /      /----------------------- /  /
//  /-----/      /---------------------------/
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://baimifan.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: Sage 2016/4/19  14:05
// +----------------------------------------------------------------------
namespace Wechat\Controller;
use Think\Controller;
use Common\Model\VideoModel;

Class MovieController extends BaseController{

    function index(){
        $this->display();
    }
    
    function detail(){
        $video_id=I("get.id");
        if($video_id==""){
            return;
        }
        $user_id = session("user_id");
        M('Video_log')->data(['video_id'=>$video_id,'user_id'=>$user_id])->add();
        $Video=new VideoModel();
        $d=$Video->relation(true)->where("video_id=$video_id")->find();
        $User=D("User");
        $headimgurl=$User->getHeadImg();
        $this->assign("headimgurl",$headimgurl);
        $this->assign("d",$d);
        $this->display();
    }
    //获取最新视频-ajax
    function getmovies(){
        $Video=new VideoModel();
        $index=I("post.i");
        $num=I("post.num");
        $d=$Video->relation("video_log")->limit($index.",".$num)->select();
        if(sizeof($d)==0){
            echo 0;
            exit();
        }
        foreach($d as $k=>$v){
            $d[$k]['detail_url']=U("Movie/detail","id=".$d[$k]["video_id"]);
            $d[$k]['log_num']=sizeof($d[$k]['video_log']);
            unset($d[$k]['video_log']);
        }
        echo json_encode($d);

    }
}